package com.manage.widgets;

import com.manage.R;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 当用户有备注信息时，点击用户名弹出的dialog
 * @author liyoro
 *
 */
public class RemarkDialog extends Dialog implements android.view.View.OnClickListener {

	private Button btnReturn = null;
	private LinearLayout layout_remard = null;

    private Window window = null;
    private Context context;
    
    private TextView tvclientName = null;
    private TextView tvphoneNumber = null;
    
    private String name = null;
    private String phone = null;
    
	public RemarkDialog(Context context, String name, String phone) {
		super(context);
		this.context = context;
		this.name = name;
		this.phone = phone;
        setContentView(R.layout.remark_dialog); 
		layout_remard  = (LinearLayout)findViewById(R.id.layout_remard);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        
        btnReturn = (Button)findViewById(R.id.MenuQuitDialogCancel);
        btnReturn.setOnClickListener(this);
		
		tvclientName = (TextView)findViewById(R.id.client_name);
		tvclientName.setText(name);
		tvphoneNumber = (TextView)findViewById(R.id.phone_number);
		tvphoneNumber.setText(phone);
		tvphoneNumber.setOnClickListener(this);
		
        //设置触摸对话框意外的地方取消对话框
        setCanceledOnTouchOutside(true);
	}
	
	@Override
	public void onClick(View v) {
		switch(v.getId()) {
		case R.id.MenuQuitDialogCancel:
			dismiss();
			break;
		case R.id.phone_number:
			Intent telIntent = new Intent(  
	                Intent.ACTION_CALL, Uri.parse("tel:"+ this.phone));
			context.startActivity(telIntent);
			break;
		default:
			break;
		}
	}

	@Override
	public void show() {
		super.show();
		windowDeploy(0, 0);
	}

	//设置窗口显示
    private void windowDeploy(int x, int y){
        window = getWindow(); //得到对话框
        window.setWindowAnimations(R.style.dialogWindowAnim); //设置窗口弹出动画
        window.setBackgroundDrawableResource(R.color.transparent); //设置对话框背景为透明
        WindowManager.LayoutParams wl = window.getAttributes();
        //根据x，y坐标设置窗口需要显示的位置
        wl.x = x; //x小于0左移，大于0右移
        wl.y = y; //y小于0上移，大于0下移  
//        wl.alpha = 0.6f; //设置透明度
//        wl.gravity = Gravity.BOTTOM; //设置重力
        window.setAttributes(wl);
    }
    
    /**
     * 添加备注信息
     * @param paramString
     */
    public void addRemark(String paramString) {
    	TextView tvRemark = new TextView(this.context);
		RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,     
                   LinearLayout.LayoutParams.WRAP_CONTENT);
		param.setMargins(60, 0, 0, 0);
		tvRemark.setLayoutParams(param);
    	tvRemark.setText("备注：" + paramString);
    	
		if(layout_remard != null && tvRemark != null) {
			layout_remard.addView(tvRemark);
		}
		
    }
}
